<template>
  <svg aria-hidden="true" :style="makeStyle" class="icon">
    <use :xlink:href="symbolId" />
  </svg>
</template>

<script lang="ts">
import { defineComponent, computed } from 'vue'
import type { CSSProperties } from 'vue'

export default defineComponent({
  name: 'SvgIcon',
  props: {
    name: {
      type: String,
      required: true
    },
    size: {
      type: [Number, String],
      default: 16
    }
  },
  setup(props) {
    const symbolId = computed(() => `#icon-${props.name}`)

    const makeStyle = computed((): CSSProperties => {
      const { size } = props
      let s = `${size}`
      s = `${s.replace('px', '')}px`

      return {
        width: s,
        height: s
      }
    })

    return { makeStyle, symbolId }
  }
})
</script>

<style lang="scss" scoped>
.icon {
  width: 1em;
  height: 1em;
  overflow: hidden;
  vertical-align: -0.15em;
  fill: currentcolor;
}
</style>
